<p>The concept of <code>Optional</code> is that it will be used when <code>null</code> could cause errors. In a way, it replaces <code>null</code>,
and when <code>Optional</code> is in use, there should never be a question of returning or receiving <code>null</code> from a call.</p>
<h2>Noncompliant Code Example</h2>
<pre>
public void doSomething () {
  Optional&lt;String&gt; optional = getOptional();
  if (optional != null) {  // Noncompliant
    // do something with optional...
  }
  Optional&lt;String&gt; text = null; // Noncompliant, a variable whose type is Optional should never itself be null
  // ...
}

@Nullable // Noncompliant
public Optional&lt;String&gt; getOptional() {
  // ...
  return null;  // Noncompliant
}
</pre>
<h2>Compliant Solution</h2>
<pre>
public void doSomething () {
  Optional&lt;String&gt; optional = getOptional();
  optional.ifPresent(
    // do something with optional...
  );
  Optional&lt;String&gt; text = Optional.empty();
  // ...
}

public Optional&lt;String&gt; getOptional() {
  // ...
  return Optional.empty();
}
</pre>

